<template>
    <div class="template-form-Lu">
        <a-modal
            title=""
            :visible="applicationFormVisible"
            :maskClosable="false"
            :closable="true"
            :destroyOnClose="true"
            width="100%"
            :dialog-style="{ margin: '0 auto' }"
            wrapClassName="form-modal-Lu"
            @cancel="closeVisible">
            <template slot="footer">
                <div v-if="linkName == '销假'">
                    <a-button class="blue-btn" @click="subForm('提交')">确认销假</a-button>
                </div>
                <div v-else-if="linkName == '数据修订'">
                    <a-button class="blue-btn" @click="editForm">确认修订</a-button>
                </div>
                <div v-else-if="linkName == '离岗申请'||linkName == '科室审批'||linkName == '分管领导审批'">
                    <a-button @click="saveForm('保存')">保存</a-button>
                    <a-button :loading="loading" class="blue-btn" @click="subForm('提交')">提交</a-button>
                    <a-button class="red-btn" @click="returnClick" v-if="linkName !== '离岗申请'">退回</a-button>
                </div>
                <div v-else>
                    <a-button class="blue-btn" @click="closeVisible">关闭</a-button>
                </div>
            </template>
            <a-tabs type="card" v-if="applicationFormVisible" @change="callback">
                <a-tab-pane key="1" tab="申请表">
                  <div id="printTest" class="print-div-shu">
                    <a-form-model
                        ref="ruleForm"
                        :model="form"
                        :rules="rules"
                    >
                        <h1 class="h1-page">自治区食品药品审评查验中心<br/>干部职工离岗请示（请假）登记表</h1>
                        <table border="1" cellspacing="0" class="table-Lu lgsq-table">
                            <tr v-if="linkName!=='离岗申请'">
                                <th>填报部门</th>
                                <td>{{ form.ftbbm }}</td>
                                <th>报送时间</th>
                                <td>{{ form.createTime }}</td>
                            </tr>
                            <tr v-if="linkName!=='离岗申请'">
                                <th>姓名</th>
                                <td>{{ form.fxm }}</td>
                                <th>职务</th>
                                <td>{{ form.fzw }}</td>
                            </tr>
                            <tr>
                                <th>离岗（请假）类型</th>
                                <td v-if="linkName=='离岗申请'||linkName=='数据修订'">
                                    <a-form-model-item ref="flglx" prop="flglx">
                                        <a-radio-group
                                            v-model:value="form.flglx"
                                            >
                                            <a-radio value="因公">
                                                因公
                                            </a-radio>
                                            <a-radio value="因私">
                                                因私
                                            </a-radio>
                                        </a-radio-group>
                                    </a-form-model-item>
                                </td>
                                <td v-else>{{ form.flglx }}</td>
                                <th>共离开</th>
                                <td v-if="linkName=='离岗申请'||linkName=='数据修订'">
                                    <a-form-model-item ref="flksj" prop="flksj">
                                        <a-select
                                        v-model="form.flksj"
                                        default-value="2"
                                        style="width: 70px"
                                        @change="handleChange">
                                        <a-select-option :value="0.5">
                                            0.5
                                        </a-select-option>
                                        <a-select-option :value="1">
                                            1
                                        </a-select-option>
                                        <a-select-option :value="1.5">
                                            1.5
                                        </a-select-option>
                                        <a-select-option :value="2">
                                            2
                                        </a-select-option>
                                        </a-select>
                                        小时
                                    </a-form-model-item>
                                </td>
                                <td v-else>{{ form.flksj }}  小时</td>
                            </tr>
                            <tr>
                                <th>离岗时间</th>
                                <td v-if="linkName=='离岗申请'||linkName=='数据修订'">
                                    <a-form-model-item ref="flgsj" prop="flgsj">
                                        <a-date-picker
                                            show-time
                                            v-model="form.flgsj"
                                            placeholder="请选择离岗时间"
                                            @change="flgsjChange"
                                        />
                                    </a-form-model-item>
                                </td>
                                <td v-else>{{ form.flgsj }}</td>
                                <th>回岗时间</th>
                                <td v-if="!form.fhgsj" style="color: grey;font-weight: 100;">自动计算，无需填写</td>
                                <td v-else>
                                    {{ form.fhgsj }}
                                </td>
                            </tr>
                            <tr>
                                <th>离岗（请假）理由</th>
                                <td v-if="linkName=='离岗申请'||linkName=='数据修订'" colspan="3">
                                    <a-form-model-item ref="flgsy" prop="flgsy">
                                        <a-textarea v-model="form.flgsy" placeholder="请输入离岗（请假）理由:" :auto-size="{ minRows: 2}"/>
                                    </a-form-model-item>
                                </td>
                                <td v-else colspan="3" class="text-align-left">{{ form.flgsy }}</td>
                            </tr>
                            <tr v-if="linkName == '离岗申请'&&form.flglx == '因公'">
                            <th>上传附件</th>
                            <td colspan="3">
                                <div>
                                    <a-form v-if="linkName == '离岗申请' || linkName == '数据修订'" layout="inline" style="display: flex;justify-content: flex-start;">
                                    <a-form-item >
                                        <a-upload style="display: inline-block;" :beforeUpload="beforeUpload" action="" @change="uploadClick">
                                            <a-button class="blue-btn">上传文件</a-button>
                                        </a-upload>
                                    </a-form-item>
                                    </a-form>
                                    <a-list item-layout="horizontal" :data-source="filesListData">
                                    <a-list-item slot="renderItem" slot-scope="item, index">
                                        <a-list-item-meta>
                                        <a @click="openFiles(item)" slot="title" href="#">{{ item.fmc }}</a>
                                        </a-list-item-meta>
                                        <a-button style="margin-right: 10px;" class="blue-btn" type="primary" @click="openFiles(item)" >预览</a-button>
                                        <a-button style="margin-right: 10px;" class="blue-btn" type="primary" @click="downloadFiles(item)" >下载文件</a-button>
                                        <a-button
                                        v-if="linkName == '离岗申请' || linkName == '数据修订'"
                                        class="red-btn"
                                        type="primary"
                                        style="margin-right: 10px;"
                                        @click="deleteFiles(item.id)" >
                                        删除文件
                                        </a-button>
                                    </a-list-item>
                                    </a-list>
                                </div>
                            </td>
                            </tr>
                            <tr>
                            <th>科室负责人意见</th>
                            <td v-if="linkName == '科室审批' || linkName == '数据修订'" colspan="3">
                                <a-form-model-item ref="fksfzryj" prop="fksfzryj">
                                    <reviewOpinions
                                      ref="reviewOpinionsRefKs"
                                      @getInputOpinion="getInputOpinion"
                                      @openOpinions="ksOpinions"
                                      v-decorator="[
                                        'fksfzryj', {initialValue:form.fksfzryj,rules: rules.fksfzryj}]"/>
                                </a-form-model-item>
                                <div v-if="linkName == '数据修订'" class="yjqm-right-bottom">
                                    <a-input
                                        @click="checkMan('fksfzrqm',form.fksfzrqm)"
                                        v-model="form.fksfzrqm"
                                        class="checkMan-Xiu"
                                        placeholder="指定科室待办人">
                                    </a-input>
                                    <a-date-picker
                                        show-time
                                        placeholder="科室负责人意见时间："
                                        v-model="form.fksfzrqmsj"
                                        @change="timeChang($event,'fksfzrqmsj')"
                                        class="checkTime-Xiu"/>
                                </div>
                            </td>
                            <td v-else colspan="3">
                                <div>
                                <p class="text-align-left">{{ form.fksfzryj }}</p>
                                <div class="yjqm-right-bottom">
                                    <img v-if="getUrl('科室审批') && form.fksfzrqmsj" :src="getUrl('科室审批')" class="yjqmImg"/>
                                    <span v-else class="yjqmImg">{{ form.fksfzrqm }}</span>
                                    <span>{{ form.fksfzrqmsj }}</span>
                                </div>
                                </div>
                            </td>
                            </tr>
                            <tr>
                            <th>分管领导意见</th>
                            <td  v-if="linkName == '分管领导审批' || linkName == '数据修订'" colspan="3">
                                <a-form-model-item ref="ffgldyj" prop="ffgldyj">
                                    <reviewOpinions
                                      ref="reviewOpinionsRefFg"
                                      @getInputOpinion="getInputOpinion"
                                      @openOpinions="fgOpinions"
                                      v-decorator="[
                                        'ffgldyj', {initialValue:form.ffgldyj,rules: rules.ffgldyj}]"/>
                                </a-form-model-item>
                                <div v-if="linkName == '数据修订'" class="yjqm-right-bottom">
                                    <a-input
                                        @click="checkMan('ffgldqm',form.ffgldqm)"
                                        v-model="form.ffgldqm"
                                        class="checkMan-Xiu"
                                        placeholder="分管领导意见人：">
                                    </a-input>
                                    <a-date-picker
                                        show-time
                                        placeholder="分管领导意见时间："
                                        v-model="form.ffgldqmsj"
                                        @change="timeChang($event,'ffgldqmsj')"
                                        class="checkTime-Xiu"/>
                                </div>
                            </td>
                            <td v-else colspan="3">
                                <div>
                                    <p class="text-align-left">{{ form.ffgldyj }}</p>
                                    <div class="yjqm-right-bottom">
                                        <img v-if="getUrl('分管领导审批') && form.ffgldqmsj" :src="getUrl('分管领导审批')" class="yjqmImg"/>
                                        <span v-else class="yjqmImg">{{ form.ffgldqm }}</span>
                                        <span>{{ form.ffgldqmsj }}</span>
                                    </div>
                                </div>
                            </td>
                            </tr>
                            <tr>
                            <th>返岗确认</th>
                            <td colspan="3">
                                <div>
                                    <p v-if="form.fxjsj" class="text-align-left">确认销假</p>
                                    <div v-if="linkName == '数据修订'" class="yjqm-right-bottom">
                                        <a-input
                                            v-model="form.fxjr"
                                            @click="checkMan('fxjr',form.fxjr)"
                                            placeholder="销假人："
                                            class="checkMan-Xiu">
                                        </a-input>
                                        <a-date-picker
                                            show-time
                                            placeholder="销假时间："
                                            v-model="form.fxjsj"
                                            @change="timeChang($event,'fxjsj')"
                                            class="checkTime-Xiu"/>
                                    </div>
                                    <div v-else class="yjqm-right-bottom">
                                        <img v-if="getUrl('销假') && form.fxjsj" :src="getUrl('销假')" class="yjqmImg"/>
                                        <span v-else class="yjqmImg">{{ form.fxjr }}</span>
                                        <span>{{ form.fxjsj }}</span>
                                    </div>
                                </div>
                            </td>
                            </tr>
                            <tr>
                            <th>备注</th>
                            <td colspan="3">
                                <p class="text-align-left" style="text-align: left;line-height: 2.5;font-size: 16px;">
                                1.因公离岗在南宁市范围内参加外单位(部门)委派工作的,须附相关证明材料。
                                    离岗1日以内(含1日)须由本科室负责人签署意见,报分管领导审批,1日以上须加报中心主任审批;<br/>
                                2.因私离岗2小时以内(含2小时)须经本科室负责人审核,并报分管领导批准;<br/>
                                3.请假结束需本人按时到办公室销假;<br/>
                                </p>
                            </td>
                            </tr>
                        </table>
                    </a-form-model>
                  </div>
                </a-tab-pane>
                <a-tab-pane v-if="linkName == '我的已办'" key="2" tab="流转记录">
                  <a-table
                    :columns="lzColumns"
                    :data-source="lzList"
                    bordered
                    style="border-color: #d9d9d9;font-weight: 600;text-align: center;"
                    :customRow="customRow">
                  </a-table>
                </a-tab-pane>
                <a-tab-pane v-if="linkName !== '离岗申请'" key="3" tab="表单附件">
                    <a-table
                        :columns="fjColumns"
                        :data-source="filesListData"
                        bordered
                        style="border-color: #d9d9d9;font-weight: 600;text-align: center;"
                        :customRow="customRow">
                        <span slot="operation_btn" slot-scope="text, record">
                        <a-button class="blue-btn" @click="openFiles(record)" style="margin-right: 10px;">查看</a-button>
                        <a-button class="blue-btn" @click="downloadFiles(record)">下载</a-button>
                        </span>
                    </a-table>
                </a-tab-pane>
                <!-- v-if="linkName == '我的已办' && form.flczt == '流程结束' && tabsKey == '1'" -->
                <a-button
                    v-if="showPrintBtn(linkName,form.flczt,tabsKey)"
                    slot="tabBarExtraContent"
                    v-print="printObj"
                    class="print-btn">
                    打印
                </a-button>
            </a-tabs>
        </a-modal>
        <personnelList ref="personnelListRef" :modaObj="modaObj" @checkPersonnel="checkPersonnel"></personnelList>
    </div>
</template>
<script>
import {initBzFlow,flowJkPage,fjupload,fjedit,openFile,downLoadOa,fjlist,deleleMinioFile,
    saveFlow,submitFlow,downMyQm,edit,fjAdd,queryAllYbJob,returnUpperzdyFlowJob,} from './service/index'
import personnelList from '../../modal/personnelList.vue'
import  moment  from 'moment'
import blobType from '@/common/blobType'
import YchConstant from '@/api/YchConstant'
export default {
    components: {
        personnelList
    },
  props:{
    formData:{
      type:[Array,Object],
      default: () => {},
      required:false
    },
    linkName:{
      type:String,
      default:'',
      required:false,
    },
    // stepNums:{
    //   type:Number,
    //   default: '',
    //   require:false,
    // },
  },
    data() {
        return {
            moment,
            loading: false,
            applicationFormVisible: false,
            tabsKey: '1',
            kongForm: {},
            form: {
              id: '',
              fuserid: '',
              oaid: '',
              jobid: '',
              ftbbm: '',
              fbssj: '',
              fxm: '',
              fzw: '',
              flglx: '',
              flgsy: '',
              flgsj: '',
              fhgsj: '',

              createBy: "",
              createTime: "",
              fbz: "",
              ffgldqm: "",
              ffgldqmsj: "",
              ffgldyj: "",
              fksfzrqm: "",
              fksfzrqmsj: "",
              fksfzryj: "",
              flczt: "",
              flksj: 2,
              fsffqlc: "",
              fuserid: "",
              fxjr: "",
              fxjsj: "",

              fdbr: '',
              fdbrid: '',
            },
            rules:{
                flgsy:
                    [{ required: true, message: '请输入离岗（请假）理由', trigger: 'blur' }],
                flgsj:
                    [{ required: true, message: '请选择离岗时间', trigger: 'change' }],
                flglx:
                    [{ required: true, message: '请选择离岗类型', trigger: 'change' }],
                fksfzryj:
                    [{ required: true, message: '请输入科室负责人意见', trigger: 'blur' }],
                ffgldyj:
                    [{ required: true, message: '请输入分管领导意见', trigger: 'blur' }],
            },
            imgList: [
              {fhjmc:'科室审批',url: ''},
              {fhjmc:'分管领导审批',url: ''},
              {fhjmc:'销假',url: ''},
            ],
            lzColumns: [
              {
                title: '环节名称',
                dataIndex: 'fhjmc',
                key: 'fhjmc',
                width: 150,
              },{
                title: '待办人',
                dataIndex: 'fdbr',
                key: 'fdbr',
                width: 150,
                align: 'center'
              },{
                title: '办理人',
                dataIndex: 'fblr',
                key: 'fblr',
                width: 100,
              },{
                title: '发送时间',
                dataIndex: 'ffssj',
                key: 'ffssj',
                width: 170,
              },{
                title: '办理时间',
                dataIndex: 'fblsj',
                key: 'fblsj',
                width: 170,
              },{
                title: '办理状态',
                dataIndex: 'fblzt',
                key: 'fblzt',
                width: 100,
              },{
                title: '办理类型',
                dataIndex: 'fbllx',
                key: 'fbllx',
                width: 300,
              },{
                title: '办理意见',
                dataIndex: 'fblyj',
                key: 'fblyj',
                align: 'center'
              },
            ],
            lzList: [],
            fjColumns: [
                {
                    title: '文件名',
                    dataIndex: 'fmc',
                    key: 'fmc',
                    align: 'center'
                },{
                    title: '文件类型',
                    dataIndex: 'fwjlx',
                    key: 'fwjlx',
                    align: 'center'
                },{
                    title: '上传时间',
                    dataIndex: 'fscsj',
                    key: 'fscsj',
                    align: 'center'
                },{
                    title: '上传人',
                    dataIndex: 'fscr',
                    key: 'fscr',
                    align: 'center'
                },{
                    title: '操作',
                    key: 'id',
                    scopedSlots: { customRender: 'operation_btn' },
                },
            ],
            filesListData: [],
            printObj:{
              id:"printTest", //需要打印的id名称
              popTitle:"干部职工离岗请示（请假）登记表",//文档的名称
              // preview:true,//预览功能，不好用
              zIndex:'20002',
              beforeOpenCallback(vue){//打印回调
              },
              openCallback (vue) {//打开之前
              },
              closeCallback (vue) {//关闭了打印工具
              },
            },
            modaObj: {},
        }
    },
    mounted(){
        this.kongForm = JSON.parse(JSON.stringify(this.form))
    },
    methods: {
        showPrintBtn(linkName,flczt,tabsKey){
            if(linkName == '我的已办' && flczt == '流程结束' && tabsKey == '1'){
                return true
            } else {
                return false
            }
        },
        closeVisible(){
            this.applicationFormVisible = false
            this.$emit('success')
            this.$refs.ruleForm.resetFields();
            this.form = JSON.parse(JSON.stringify(this.kongForm))
            this.filesListData = []
        },
        callback(key) {
            // //console.log(key);
            this.tabsKey = key
        },
        timeChang(val,name){
            let data = this.form
            data[name] = moment(val).format('YYYY-MM-DD HH:mm:ss')
        },
        checkMan(place,man){
            this.$nextTick(_ => {
                this.modaObj = {place: place,manList: man}
                this.$refs.personnelListRef.personnelListVisible = true
            })
        },
        // 选择人员
        checkPersonnel(place,id,name){
            //console.log(place,id,name)
            this.$refs.personnelListRef.personnelListVisible = false
            //console.log('-------------------')
            const data = this.form
            data[place] = name.toString()
            let fdbrid = id.toString()
            let fdbr = name.toString()
            let Data = {
                jobid: this.form.jobid,
                fdbrid: id.toString(),
                fdbr: name.toString()
            }
        },
        customRow() {
        return {
            style: {
                'font-size' : '16px',
                'text-align' : 'center'
            },
        }
        },
        beforeUpload(e){
        return false
        },
        // 上传附件
        async uploadClick({file}){
        //console.log(file)
        //console.log(this.form)
        if(!this.form.id){
            let data = []
            data = {
                id: this.form.id,
                ftbbm: this.form.ftbbm,
                fbssj: this.form.fbssj,
                fxm: this.form.fxm,
                fzw: this.form.fzw,
                flglx: this.form.flglx,
                flgsy: this.form.flgsy,
                flgsj: this.form.flgsj,
                fhgsj: this.form.fhgsj,
                flksj: this.form.flksj
            }
            const res = await fjAdd(data)
            this.form = res.result
            this.form.id = res.result.id
            if (res.success) {
            this.uploadClicka(file,this.form.id)
            }
        } else {
            this.uploadClicka(file,this.form.id)
        }
        },
        uploadClicka(file,id){
        //console.log(file)
        var that = this
            if(typeof file.uid !== 'undefined') {
            const fileData = new FormData();
            fileData.append("file",file);
            fileData.append("oaid",id);
            //console.log(fileData)
            fjupload(fileData).then(res => {
                //console.log('fileData',res)
                if (res.success) {
                that.$message.success(res.message)
                fjlist({foaid:id}).then(res => {
                    that.filesListData = []
                    that.filesListData = res.result.records
                })
                } else {
                that.$message.warning(res.message)
                }
            })
            }
        },
        // 预览
        openFiles(item){
          if(item.fwjlx.indexOf('pdf') !== -1){
              //console.log()
              window.open(
                  bootConfig[process.env.NODE_ENV].locality_ApI2+YchConstant.SPZX_OA+'/oaFjzyk/downLoadOa?id='+item.id
              )
            } else {
              openFile({id:item.id}).then(res => {
                if(!res.success){
                      this.$message.warning('当前附件类型不支持预览,请下载查看')
                } else {
                    window.open(res.result.wordUrl, '_blank')
                }
              })
            }
        },
        // 下载附件
        downloadFiles(val){
          //console.log('下载',val)
          var that = this
          var fileName = val.fmc
          downLoadOa({id:val.id}).then((data) => {
            // //console.log(data)
              if (!data) {
                  that.$message.warning('文件下载失败')
                  return
              }
              let url = window.URL.createObjectURL(new Blob([data], { type: blobType.type[blobType.suffix.indexOf(val.fwjlx)] }))
              let link = document.createElement('a')
              link.style.display = 'none'
              link.href = url
              link.setAttribute('download', fileName)
              document.body.appendChild(link)
              link.click()
              document.body.removeChild(link) //下载完成移除元素
              window.URL.revokeObjectURL(url) //释放掉blob对象
              // this.vxModal.visabled = false;
          })
        },
        // 删除附件
        deleteFiles(idd){
            //console.log('idd',idd)
            deleleMinioFile({id:idd}).then(res => {
            if(res.code == 200){
              this.$message.success('删除成功')
              fjlist({foaid:this.form.id}).then(res => {
                this.filesListData = []
                this.filesListData = res.result.records
              })
            } else {
              this.$message.warning(res.message)
            }
          })
        },
            // 选择离岗小时数
    handleChange(value) {
            //console.log(this.linkName)
            //console.log('离岗申请')
      if(this.form.flgsj !== ''){
        var haomiao = value * 3600000
        var stime = Date.parse(new Date(this.form.flgsj));
        var ztime = Number(stime) + Number(haomiao)
        var htime = new Date(ztime)
        // //console.log()

        this.form.fhgsj = moment(htime).format('YYYY-MM-DD HH:mm:ss')
        //console.log(this.form.fhgsj)
      }
    },
    // 离岗时间
    flgsjChange(val){
        //console.log(val)
      this.form.flgsj = val==null?'':moment(val).format('YYYY-MM-DD HH:mm:ss')
      // var stime = Date.parse(new Date(this.form.flgsj));
      if(val == null){
        this.form.fhgsj = ''
      }
      if(this.form.flksj !== 0 && val !== null){
        var haomiao = this.form.flksj * 3600000
        var stime = Date.parse(new Date(this.form.flgsj));
        var ztime = Number(stime) + Number(haomiao)
        var htime = new Date(ztime)

        this.form.fhgsj = moment(htime).format('YYYY-MM-DD HH:mm:ss')
        // //console.log(this.form.fhgsj)
      }
    },
        // 打开意见弹窗
        ksOpinions(){
          this.$refs.reviewOpinionsRefKs.getData({opinionType:'ksIdeaType',oldVal:this.form.fksfzryj,valueData:{hjmc:'fksfzryj'}})
        },
        fgOpinions(){
          this.$refs.reviewOpinionsRefFg.getData({opinionType:'fgIdeaType',oldVal:this.form.ffgldyj,valueData:{hjmc:'ffgldyj'}})
        },
        // 意见弹窗
        getInputOpinion(val,valueData){
          let data = this.form
          data[valueData.hjmc] = val
          this.cform.setFieldsValue({
            fksfzryj:this.form.fksfzryj,
            ffgldyj: this.form.ffgldyj,
          });
        },
        // 获取签名图片
        getUrl(ids){
          let url = ''
          this.imgList.forEach(item => {
            if(item.fhjmc == ids){
              url = item.url
            }
          })
          // //console.log('长度',url.length)
          return url
        },
        saveForm(str){
          let data = {}
          if(str == '保存'){
              if(this.linkName == '离岗申请'){
                  data = {
                      id: this.form.id,
                      ftbbm: this.form.ftbbm,
                      fbssj: this.form.fbssj,
                      fxm: this.form.fxm,
                      fzw: this.form.fzw,
                      flglx: this.form.flglx,
                      flgsy: this.form.flgsy,
                      flgsj: moment(this.form.flgsj).format("YYYY-MM-DD HH:mm:ss"),
                      fhgsj: this.form.fhgsj,
                      flksj: this.form.flksj,
                      fuserid: this.form.fuserid,
                  }
                  this.shenQing(data,str)
              } else if(this.linkName == '科室审批'){
                  data = {
                      jobid: this.formData.jobid,
                      oaid: this.formData.oaid,
                      lcmbCode: '',
                      nextNodeId: '',
                      nextNode: '',
                      currentNode: '',
                      dbrid: '',
                      smgflag: '',
                      map: {
                          fksfzrqm: this.form.fksfzrqm,
                          fksfzrqmsj: this.form.fksfzrqmsj,
                          fksfzryj: this.form.fksfzryj,
                      },
                      opinion: this.form.fksfzryj,
                  }
                  this.baoCun(data)
              } else if(this.linkName == '分管领导审批'){
                  data = {
                      jobid: this.formData.jobid,
                      oaid: this.formData.oaid,
                      lcmbCode: '',
                      nextNodeId: '',
                      nextNode: '',
                      currentNode: '',
                      dbrid: '',
                      smgflag: '',
                      map: {
                          ffgldqm: this.form.ffgldqm,
                          ffgldqmsj: this.form.ffgldqmsj,
                          ffgldyj: this.form.ffgldyj,
                      },
                      opinion: this.form.ffgldyj,
                  }
                  this.baoCun(data)
              } else if(this.linkName == '销假'){
                  data = {
                      jobid: this.formData.jobid,
                      oaid: this.formData.oaid,
                      lcmbCode: '',
                      nextNodeId: '',
                      nextNode: '',
                      currentNode: '',
                      dbrid: '',
                      smgflag: '',
                      map: {
                          fxjr: this.form.fxjr,
                          fxjsj: this.form.fxjsj,
                      },
                      opinion: '同意',
                  }
                  this.baoCun(data)
              }
          } else if (str == '提交'){
              if(this.linkName == '离岗申请'){
                this.loading = true
                  if(this.form.id){
                      data = {
                          jobid: this.form.jobid,
                          oaid: this.form.id,
                          lcmbCode: '',
                          nextNodeId: '',
                          nextNode: '',
                          currentNode: '',
                          dbrid: '',
                          smgflag: '',
                          map: {
                              ftbbm: this.form.ftbbm,
                              fbssj: this.form.fbssj,
                              fxm: this.form.fxm,
                              fzw: this.form.fzw,
                              flglx: this.form.flglx,
                              flgsy: this.form.flgsy,
                              flgsj: moment(this.form.flgsj).format("YYYY-MM-DD HH:mm:ss"),
                              fhgsj: this.form.fhgsj,
                              flksj: this.form.flksj,
                          },
                      }
                      if(this.form.jobid){
                          this.tiJiao(data)
                      } else {
                          data = {
                              id: this.form.id,
                              ftbbm: this.form.ftbbm,
                              fbssj: this.form.fbssj,
                              fxm: this.form.fxm,
                              fzw: this.form.fzw,
                              flglx: this.form.flglx,
                              flgsy: this.form.flgsy,
                              flgsj: moment(this.form.flgsj).format("YYYY-MM-DD HH:mm:ss"),
                              fhgsj: this.form.fhgsj,
                              flksj: this.form.flksj,
                              fuserid: this.form.fuserid,
                          }
                          this.shenQing(data,'保提')
                      }
                  } else {
                      data = {
                          id: this.form.id,
                          ftbbm: this.form.ftbbm,
                          fbssj: this.form.fbssj,
                          fxm: this.form.fxm,
                          fzw: this.form.fzw,
                          flglx: this.form.flglx,
                          flgsy: this.form.flgsy,
                          flgsj: moment(this.form.flgsj).format("YYYY-MM-DD HH:mm:ss"),
                          fhgsj: this.form.fhgsj,
                          flksj: this.form.flksj,
                          fsffqlc: '是'
                      }
                      this.shenQing(data,str)
                  }
              } else if(this.linkName == '科室审批'){
                  data = {
                      jobid: this.formData.jobid,
                      oaid: this.formData.oaid,
                      lcmbCode: '',
                      nextNodeId: '',
                      nextNode: '',
                      currentNode: '',
                      dbrid: '',
                      smgflag: '',
                      map: {
                          fksfzrqm: this.form.fksfzrqm,
                          fksfzrqmsj: this.form.fksfzrqmsj,
                          fksfzryj: this.form.fksfzryj,
                      },
                      opinion: this.form.fksfzryj,
                  }
                  this.tiJiao(data)
              } else if(this.linkName == '分管领导审批'){
                  data = {
                      jobid: this.formData.jobid,
                      oaid: this.formData.oaid,
                      lcmbCode: '',
                      nextNodeId: '',
                      nextNode: '',
                      currentNode: '',
                      dbrid: '',
                      smgflag: '',
                      map: {
                          ffgldqm: this.form.ffgldqm,
                          ffgldqmsj: this.form.ffgldqmsj,
                          ffgldyj: this.form.ffgldyj,
                      },
                      opinion: this.form.ffgldyj,
                  }
                  this.tiJiao(data)
              } else if(this.linkName == '销假'){
                  data = {
                      jobid: this.formData.jobid,
                      oaid: this.formData.oaid,
                      lcmbCode: '',
                      nextNodeId: '',
                      nextNode: '',
                      currentNode: '',
                      dbrid: '',
                      smgflag: '',
                      map: {
                          fxjr: this.form.fxjr,
                          fxjsj: this.form.fxjsj,
                      },
                      opinion: '同意',
                  }
                  this.tiJiao(data)
              }
          }
        },
        subForm(str){
            this.$refs.ruleForm.validate(valid => {
                if(valid) {
                    var that = this
                    that.$confirm({
                        title: '您确定要提交吗?',
                        onOk() {
                            let data = {}
                            if(str == '保存'){
                                if(that.linkName == '离岗申请'){
                                    data = {
                                        id: that.form.id,
                                        ftbbm: that.form.ftbbm,
                                        fbssj: that.form.fbssj,
                                        fxm: that.form.fxm,
                                        fzw: that.form.fzw,
                                        flglx: that.form.flglx,
                                        flgsy: that.form.flgsy,
                                        flgsj: moment(that.form.flgsj).format("YYYY-MM-DD HH:mm:ss"),
                                        fhgsj: that.form.fhgsj,
                                        flksj: that.form.flksj,
                                        fuserid: that.form.fuserid,
                                    }
                                    that.shenQing(data,str)
                                } else if(that.linkName == '科室审批'){
                                    data = {
                                        jobid: that.formData.jobid,
                                        oaid: that.formData.oaid,
                                        lcmbCode: '',
                                        nextNodeId: '',
                                        nextNode: '',
                                        currentNode: '',
                                        dbrid: '',
                                        smgflag: '',
                                        map: {
                                            fksfzrqm: that.form.fksfzrqm,
                                            fksfzrqmsj: that.form.fksfzrqmsj,
                                            fksfzryj: that.form.fksfzryj,
                                        },
                                        opinion: that.form.fksfzryj,
                                    }
                                    that.baoCun(data)
                                } else if(that.linkName == '分管领导审批'){
                                    data = {
                                        jobid: that.formData.jobid,
                                        oaid: that.formData.oaid,
                                        lcmbCode: '',
                                        nextNodeId: '',
                                        nextNode: '',
                                        currentNode: '',
                                        dbrid: '',
                                        smgflag: '',
                                        map: {
                                            ffgldqm: that.form.ffgldqm,
                                            ffgldqmsj: that.form.ffgldqmsj,
                                            ffgldyj: that.form.ffgldyj,
                                        },
                                        opinion: that.form.ffgldyj,
                                    }
                                    that.baoCun(data)
                                } else if(that.linkName == '销假'){
                                    data = {
                                        jobid: that.formData.jobid,
                                        oaid: that.formData.oaid,
                                        lcmbCode: '',
                                        nextNodeId: '',
                                        nextNode: '',
                                        currentNode: '',
                                        dbrid: '',
                                        smgflag: '',
                                        map: {
                                            fxjr: that.form.fxjr,
                                            fxjsj: that.form.fxjsj,
                                        },
                                        opinion: '同意',
                                    }
                                    that.baoCun(data)
                                }
                            } else if (str == '提交'){
                                if(that.linkName == '离岗申请'){
                                that.loading = true
                                    if(that.form.id){
                                        data = {
                                            jobid: that.form.jobid,
                                            oaid: that.form.id,
                                            lcmbCode: '',
                                            nextNodeId: '',
                                            nextNode: '',
                                            currentNode: '',
                                            dbrid: '',
                                            smgflag: '',
                                            map: {
                                                ftbbm: that.form.ftbbm,
                                                fbssj: that.form.fbssj,
                                                fxm: that.form.fxm,
                                                fzw: that.form.fzw,
                                                flglx: that.form.flglx,
                                                flgsy: that.form.flgsy,
                                                flgsj: moment(that.form.flgsj).format("YYYY-MM-DD HH:mm:ss"),
                                                fhgsj: that.form.fhgsj,
                                                flksj: that.form.flksj,
                                            },
                                        }
                                        if(that.form.jobid){
                                            that.tiJiao(data)
                                        } else {
                                            data = {
                                                id: that.form.id,
                                                ftbbm: that.form.ftbbm,
                                                fbssj: that.form.fbssj,
                                                fxm: that.form.fxm,
                                                fzw: that.form.fzw,
                                                flglx: that.form.flglx,
                                                flgsy: that.form.flgsy,
                                                flgsj: moment(that.form.flgsj).format("YYYY-MM-DD HH:mm:ss"),
                                                fhgsj: that.form.fhgsj,
                                                flksj: that.form.flksj,
                                                fuserid: that.form.fuserid,
                                            }
                                            that.shenQing(data,'保提')
                                        }
                                    } else {
                                        data = {
                                            id: that.form.id,
                                            ftbbm: that.form.ftbbm,
                                            fbssj: that.form.fbssj,
                                            fxm: that.form.fxm,
                                            fzw: that.form.fzw,
                                            flglx: that.form.flglx,
                                            flgsy: that.form.flgsy,
                                            flgsj: moment(that.form.flgsj).format("YYYY-MM-DD HH:mm:ss"),
                                            fhgsj: that.form.fhgsj,
                                            flksj: that.form.flksj,
                                            fsffqlc: '是'
                                        }
                                        that.shenQing(data,str)
                                    }
                                } else if(that.linkName == '科室审批'){
                                    data = {
                                        jobid: that.formData.jobid,
                                        oaid: that.formData.oaid,
                                        lcmbCode: '',
                                        nextNodeId: '',
                                        nextNode: '',
                                        currentNode: '',
                                        dbrid: '',
                                        smgflag: '',
                                        map: {
                                            fksfzrqm: that.form.fksfzrqm,
                                            fksfzrqmsj: that.form.fksfzrqmsj,
                                            fksfzryj: that.form.fksfzryj,
                                        },
                                        opinion: that.form.fksfzryj,
                                    }
                                    that.tiJiao(data)
                                } else if(that.linkName == '分管领导审批'){
                                    data = {
                                        jobid: that.formData.jobid,
                                        oaid: that.formData.oaid,
                                        lcmbCode: '',
                                        nextNodeId: '',
                                        nextNode: '',
                                        currentNode: '',
                                        dbrid: '',
                                        smgflag: '',
                                        map: {
                                            ffgldqm: that.form.ffgldqm,
                                            ffgldqmsj: that.form.ffgldqmsj,
                                            ffgldyj: that.form.ffgldyj,
                                        },
                                        opinion: that.form.ffgldyj,
                                    }
                                    that.tiJiao(data)
                                } else if(that.linkName == '销假'){
                                    data = {
                                        jobid: that.formData.jobid,
                                        oaid: that.formData.oaid,
                                        lcmbCode: '',
                                        nextNodeId: '',
                                        nextNode: '',
                                        currentNode: '',
                                        dbrid: '',
                                        smgflag: '',
                                        map: {
                                            fxjr: that.form.fxjr,
                                            fxjsj: that.form.fxjsj,
                                        },
                                        opinion: '同意',
                                    }
                                    that.tiJiao(data)
                                }
                            }
                        },
                        onCancel() {},
                    });
                }
            })
        },
        shenQing(data,str){
            initBzFlow(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                    if(str == '提交'){
                        this.closeVisible()
                    } else {
                        this.form = {
                            ...res.result.oaMap,
                            jobid: res.result.jobMap.id
                        }
                        this.form.id = res.result.oaMap.id//赋值
                    }
                } else {
                    this.$message.warning(res.message)
                }
                if(str == '保提'){
                    let data = {
                        jobid: this.form.jobid,
                        oaid: this.form.id,
                        lcmbCode: '',
                        nextNodeId: '',
                        nextNode: '',
                        currentNode: '',
                        dbrid: '',
                        smgflag: '',
                        map: {
                            ftbbm: this.form.ftbbm,
                            fbssj: this.form.fbssj,
                            fxm: this.form.fxm,
                            fzw: this.form.fzw,
                            flglx: this.form.flglx,
                            flgsy: this.form.flgsy,
                            flgsj: moment(this.form.flgsj).format("YYYY-MM-DD HH:mm:ss"),
                            fhgsj: this.form.fhgsj,
                            flksj: this.form.flksj,
                        },
                    }
                    this.tiJiao(data)
                }
                this.loading = false
            })
        },
        baoCun(data){
            saveFlow(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                } else {
                    this.$message.warning(res.message)
                }
            })
        },
        tiJiao(data){
            submitFlow(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.closeVisible()
                } else {
                    this.$message.warning(res.message)
                }
                this.loading = false
            })
        },
        saveFormbbb(str){
            this.$refs.ruleForm.validate(valid => {
                if(valid) {
                    let data = {}
                    if(this.linkName == '离岗申请'){
                        if(this.form.id){
                            data = {
                                jobid: this.form.jobid,
                                oaid: this.form.id,
                                lcmbCode: '',
                                nextNodeId: '',
                                nextNode: '',
                                currentNode: '',
                                dbrid: '',
                                smgflag: '',
                                map: {
                                    ftbbm: this.form.ftbbm,
                                    fbssj: this.form.fbssj,
                                    fxm: this.form.fxm,
                                    fzw: this.form.fzw,
                                    flglx: this.form.flglx,
                                    flgsy: this.form.flgsy,
                                    flgsj: moment(this.form.flgsj).format("YYYY-MM-DD HH:mm:ss"),
                                    fhgsj: this.form.fhgsj,
                                    flksj: this.form.flksj,
                                },
                            }
                        if(str == '保存'){
                            saveFlow(data).then(res => {
                            // //console.log(res)
                            if(res.code == 200){
                                this.$message.success(res.message)
                            } else {
                                this.$message.warning(res.message)
                            }
                            })
                        } else if(str == '提交') {
                            submitFlow(data).then(res => {
                            // //console.log(res)
                            if(res.code == 200){
                                this.$message.success(res.message)
                                this.closeVisible()
                            } else {
                                this.$message.warning(res.message)
                            }
                            })
                        }
                        } else {
                            data = {
                                id: this.form.id,
                                ftbbm: this.form.ftbbm,
                                fbssj: this.form.fbssj,
                                fxm: this.form.fxm,
                                fzw: this.form.fzw,
                                flglx: this.form.flglx,
                                flgsy: this.form.flgsy,
                                flgsj: moment(this.form.flgsj).format("YYYY-MM-DD HH:mm:ss"),
                                fhgsj: this.form.fhgsj,
                                flksj: this.form.flksj,
                            }
                            if(str == '提交'){
                                data = {
                                ...data,
                                fsffqlc: '是'
                                }
                            }
                            // //console.log('data',data)
                            initBzFlow(data).then(res => {
                                // //console.log('保存',res)
                                if(res.code == 200){
                                this.$message.success(res.message)
                                if(str == '提交'){
                                    this.closeVisible()
                                } else {
                                    this.form = {
                                        ...res.result.oaMap,
                                        jobid: res.result.jobMap.id
                                    }
                                    this.form.id = res.result.oaMap.id//赋值
                                }
                                } else {
                                    this.$message.warning(res.message)
                                }
                            })
                        }
                    } else if (this.linkName == '科室审批'){
                        data = {
                            jobid: this.formData.jobid,
                            oaid: this.formData.oaid,
                            lcmbCode: '',
                            nextNodeId: '',
                            nextNode: '',
                            currentNode: '',
                            dbrid: '',
                            smgflag: '',
                            map: {
                                fksfzrqm: this.form.fksfzrqm,
                                fksfzrqmsj: this.form.fksfzrqmsj,
                                fksfzryj: this.form.fksfzryj,
                            },
                            opinion: this.form.fksfzryj,
                        }
                    } else if (this.linkName == '分管领导审批'){
                        data = {
                            jobid: this.formData.jobid,
                            oaid: this.formData.oaid,
                            lcmbCode: '',
                            nextNodeId: '',
                            nextNode: '',
                            currentNode: '',
                            dbrid: '',
                            smgflag: '',
                            map: {
                                ffgldqm: this.form.ffgldqm,
                                ffgldqmsj: this.form.ffgldqmsj,
                                ffgldyj: this.form.ffgldyj,
                            },
                            opinion: this.form.ffgldyj,
                        }
                    } else if (this.linkName == '销假'){
                        data = {
                            jobid: this.formData.jobid,
                            oaid: this.formData.oaid,
                            lcmbCode: '',
                            nextNodeId: '',
                            nextNode: '',
                            currentNode: '',
                            dbrid: '',
                            smgflag: '',
                            map: {
                                fxjr: this.form.fxjr,
                                fxjsj: this.form.fxjsj,
                            },
                            opinion: '同意',
                        }
                    }
                    if(str == '保存' && this.linkName !== '离岗申请'){
                        saveFlow(data).then(res => {
                        if(res.code == 200){
                            this.$message.success(res.message)
                        } else {
                            this.$message.warning(res.message)
                        }
                        })
                    } else if(str == '提交' && this.linkName !== '离岗申请'){
                        submitFlow(data).then(res => {
                        if(res.code == 200){
                            this.$message.success(res.message)
                            this.closeVisible()
                        } else {
                            this.$message.warning(res.message)
                        }
                        })
                    }
                }
            })
        },
        // 编辑
        editForm(){
            let data = {
                fbssj : this.form.fbssj,
                fbz : this.form.fbz,
                ffgldqm : this.form.ffgldqm,
                ffgldqmsj : this.form.ffgldqmsj,
                ffgldyj : this.form.ffgldyj,
                fhgsj : this.form.fhgsj,
                fksfzrqm : this.form.fksfzrqm,
                fksfzrqmsj : this.form.fksfzrqmsj,
                fksfzryj : this.form.fksfzryj,
                flczt : this.form.flczt,
                flglx : this.form.flglx,
                flgsj : this.form.flgsj,
                flgsy : this.form.flgsy,
                flksj: this.form.flksj,
                fsffqlc : this.form.fsffqlc,
                ftbbm : this.form.ftbbm,
                fuserid : this.form.fuserid,
                fxjr : this.form.fxjr,
                fxjsj : this.form.fxjsj,
                fxm : this.form.fxm,
                fzw : this.form.fzw,
                id : this.form.id,
                opinion : this.form.opinion,
                jobid: this.form.jobid,
                fdbrid: this.form.fdbrid,
                fdbr: this.form.fdbr
            }
            edit(data).then(res => {
                //console.log(res)
                if(res.code == 200){
                this.$message.success(res.message)
                // this.closeVisible()
                } else {
                this.$message.warning(res.message)
                }
            })
        },
        // 退回意见确认
        returnClick(){
            this.$refs.ruleForm.validate(valid => {
                if (valid){
                    queryAllYbJob({jobid:this.form.jobid}).then(res => {
                        let list = res.result
                        list.forEach(item => {
                            if(item.fhjmc == '离岗申请'){
                                this.returnFuntion(this.form.jobid,item.id)
                            }
                        })
                    })
                }
            })
        },
        returnFuntion(jobid,ids){
            let returnStr = ''
            if(this.linkName == '科室审批'){
                returnStr = this.form.fksfzryj
            } else if(this.linkName == '分管领导审批'){
                returnStr = this.form.ffgldyj
            }
            let data = {
                jobid: jobid,
                opinion: returnStr,
                shjid: ids,
                smgflag: '',
                smsContent: '',
            }
            returnUpperzdyFlowJob(data).then(res => {
                if(res.code == 200){
                    this.$message.success(res.message)
                    this.closeVisible()
                } else {
                    this.$message.error(res.message)
                }
            })
        },
    },
    watch: {
        formData:{
            handler (newval, oldVal) {
            this.form = {...newval}
            //console.log('form',this.form)
            if(this.linkName == '离岗申请'){
                this.form.flgsj = this.form.flgsj ? moment(this.form.flgsj):''
            }
            this.filesListData = []
            // //console.log('form',this.form)

            let id = this.form.oaid
            flowJkPage({oaid:id}).then(res => {
                let arr1 = []
                    arr1 = res.result.records
                var arr2 = new Array();
                for (let i = arr1.length - 1; i >= 0; i--) {
                    arr2.push(arr1[i]);
                }
                this.lzList = []
                arr1.forEach(item => {
                    item = {
                        ...item,
                        key: item.jobid
                    }
                    this.lzList.push(item)
                    this.imgList.forEach((items,a)=> {
                        if(item.fdbrid){
                        if(items.fhjmc == item.fhjmc){
                            downMyQm({id:item.fdbrid}).then(resa => {
                              if(resa.code){
                                this.imgList[a].url = null
                              } else {
                                this.imgList[a].url = "data:image/png;base64," +
                                btoa( new Uint8Array(resa).reduce( (data, byte) => data + String.fromCharCode(byte), "" ))
                              }
                            })
                        }
                        } else {}
                    })
                })
            })
            if(id){
              fjlist({foaid:id}).then(res => {
                this.filesListData = []
                this.filesListData = res.result.records
              })
            }
            // if(this.linkName == '数据修订'){
            //   this.getqueryAllYbJob()
            //   this.returnYj = ''
            // }
            },
            deep: true
        },
    },
}
</script>
<style>
@import url('../../css/oaLess.css');
@import url('../../css/oaClass.css');
</style>
